package com.boge.modules.house.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.boge.modules.house.entity.TCityEntity;
import com.boge.modules.house.entity.TProvinceEntity;
import com.boge.modules.house.service.TCityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.boge.modules.house.entity.TAreaEntity;
import com.boge.modules.house.service.TAreaService;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.R;



/**
 * 
 *
 * @author boge
 * @email dengpbs@163.com
 * @date 2024-12-13 01:03:40
 */
@RestController
@RequestMapping("house/tarea")
public class TAreaController {
    @Autowired
    private TAreaService tAreaService;

    @Autowired
    private TCityService cityService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("house:tarea:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tAreaService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/queryByCityId/{id}")
    //@RequiresPermissions("house:tcity:list")
    public R queryByCityId(@PathVariable("id") String id ){
        // 传递的是 省份的id 需要获取对应的code
        TCityEntity cityEntity = cityService.getById(id);
        List<TAreaEntity> citys = tAreaService.list(new LambdaQueryWrapper<TAreaEntity>()
                .eq(TAreaEntity::getCityCode,cityEntity.getCode()));

        return R.ok().put("areas", citys);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("house:tarea:info")
    public R info(@PathVariable("id") Integer id){
		TAreaEntity tArea = tAreaService.getById(id);

        return R.ok().put("tArea", tArea);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("house:tarea:save")
    public R save(@RequestBody TAreaEntity tArea){
		tAreaService.save(tArea);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("house:tarea:update")
    public R update(@RequestBody TAreaEntity tArea){
		tAreaService.updateById(tArea);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("house:tarea:delete")
    public R delete(@RequestBody Integer[] ids){
		tAreaService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
